#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os.path
import gtk
import thread, threading

class Thumbnailer(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.lock = threading.Lock()
        self.photo = None
    
    def run(self):
        self.lock.acquire()
        i = 0
        while i < len(PhotoFlip.photos_list):
            print "coucou"
            load_photo(photos_list[i])
            
    
    def load_photo(self, photofromlist):
        try:
            self.photo = gtk.gdk.pixbuf_new_from_file(photofromlist[1])
        except Exception:
            print "Unable to load photo"

        photofromlist[0] = clutter.Texture(self.thumbnailer.photo)
        (w, h) = photofromlist[0].get_size()
            
        if w / h >= 3 / 2:
            width = 300
            height = int(width / (float(w) / h))
        else:
            height = 200
            width = int(height / (float(h) / w))
            
        photofromlist[0].set_size(width, height)
        photofromlist[0].show()
        self.stage.add(photofromlist[0])

        self.lock.release()

        self.join()

